package com.hugh.dubbo.service.provider.com.hugh.dubbo.provide.impl;

import com.hugh.dubbo.api.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Author: Hugh
 * @Date: 2020/7/4
 */
@Component
@Service(interfaceClass = HelloService.class)
@Slf4j
public class HellServiceImpl implements HelloService {

    @Override
    public String sayHello2Me(String name) {
        sleepTime(100L);
        return "hi! " + name +"this is sayHello2Me";
    }

    @Override
    public String sayHello2You(String name) {
        sleepTime(100L);
        return "hi! " + name + "this is sayHello2You";
    }

    @Override
    public String sayHello2All(String name) {
        sleepTime(100L);
        return "hi! " + name + "this is sayHello2All";
    }

    private void sleepTime(long maxTime){
        try {
            Thread.sleep(ThreadLocalRandom.current().nextLong(maxTime));
        }
        catch (Exception e){
            return;
        }
    }
}
